Add fossil VCS support to `cargo new`
authorDavid King <dking@ketralnis.com>
Sat, 10 Jun 2017 00:51:56 +0000 (17:51 -0700)
committerDavid King <dking@ketralnis.com>
Sat, 10 Jun 2017 01:03:28 +0000 (18:03 -0700)
Fossil is a simple, high-reliability, distributed software configuration
management system <https://www.fossil-scm.org/>

src/bin/new.rs
src/cargo/ops/cargo_new.rs
src/cargo/util/mod.rs
src/cargo/util/vcs.rs

index aeee334a9651f75a7d8e3b69c55ccf531029ffe4..dfa3668076dab7893fd5c6f46a53263d4d9e81c5 100644 (file)
@@ -27,8 +27,9 @@ Usage:
 Options:
     -h, --help          Print this message
     --vcs VCS           Initialize a new repository for the given version
-                        control system (git, hg, or pijul) or do not initialize any version
-                        control at all (none) overriding a global configuration.
+                        control system (git, hg, pijul, or fossil) or do not
+                        initialize any version control at all (none), overriding
+                        a global configuration.
     --bin               Use a binary (application) template
     --lib               Use a library template [default]
     --name NAME         Set the resulting package name, defaults to the value of <path>
index 846e7c0d4448740aadbbe3d6b402a59b8e2b71a6..b41aee94adecf1fe327dbac9eab7805b8c99222b 100644 (file)
@@ -12,14 +12,14 @@ use term::color::BLACK;
 
 use core::Workspace;
 use ops::is_bad_artifact_name;
-use util::{GitRepo, HgRepo, PijulRepo, internal};
+use util::{GitRepo, HgRepo, PijulRepo, FossilRepo, internal};
 use util::{Config, paths};
 use util::errors::{CargoError, CargoResult, CargoResultExt};
 
 use toml;
 
 #[derive(Clone, Copy, Debug, PartialEq)]
-pub enum VersionControl { Git, Hg, Pijul, NoVcs }
+pub enum VersionControl { Git, Hg, Pijul, Fossil, NoVcs }
 
 pub struct NewOptions<'a> {
     pub version_control: Option<VersionControl>,
@@ -49,6 +49,7 @@ impl Decodable for VersionControl {
             "git" => VersionControl::Git,
             "hg" => VersionControl::Hg,
             "pijul" => VersionControl::Pijul,
+            "fossil" => VersionControl::Fossil,
             "none" => VersionControl::NoVcs,
             n => {
                 let err = format!("could not decode '{}' as version control", n);
@@ -340,13 +341,17 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> {
             num_detected_vsces += 1;
         }
 
+        if fs::metadata(&path.join(".fossil")).is_ok() {
+            version_control = Some(VersionControl::Fossil);
+            num_detected_vsces += 1;
+        }
+
         // if none exists, maybe create git, like in `cargo new`
 
         if num_detected_vsces > 1 {
-            bail!("more than one of .hg, .git, or .pijul directories found \
-                              and the ignore file can't be \
-                              filled in as a result, \
-                              specify --vcs to override detection");
+            bail!("more than one of .hg, .git, .pijul, .fossil configurations \
+                              found and the ignore file can't be filled in as \
+                              a result. specify --vcs to override detection");
         }
     }
 
@@ -415,6 +420,11 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
                 PijulRepo::init(path, config.cwd())?;
             }
         },
+        VersionControl::Fossil => {
+            if !fs::metadata(&path.join(".fossil")).is_ok() {
+                FossilRepo::init(path, config.cwd())?;
+            }
+        },
         VersionControl::NoVcs => {
             fs::create_dir_all(path)?;
         },
index b1eda3cabeb90360d749b3471ac53b500a6b9f93..9c1c9c5e0642ddbd2317c3e79c14bcb2ff657fcc 100644 (file)
@@ -16,7 +16,7 @@ pub use self::rustc::Rustc;
 pub use self::sha256::Sha256;
 pub use self::to_semver::ToSemver;
 pub use self::to_url::ToUrl;
-pub use self::vcs::{GitRepo, HgRepo, PijulRepo};
+pub use self::vcs::{GitRepo, HgRepo, PijulRepo, FossilRepo};
 pub use self::read2::read2;
 
 pub mod config;
index 61a4b1c394292a3552d27eb552b732da9684dfd5..1d3188e26301fc058c533dd4d57f82fc354bc6e8 100644 (file)
@@ -1,4 +1,5 @@
 use std::path::Path;
+use std::fs::create_dir;
 
 use git2;
 
@@ -7,6 +8,7 @@ use util::{CargoResult, process};
 pub struct HgRepo;
 pub struct GitRepo;
 pub struct PijulRepo;
+pub struct FossilRepo;
 
 impl GitRepo {
     pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
@@ -35,3 +37,30 @@ impl PijulRepo {
         Ok(PijulRepo)
     }
 }
+
+impl FossilRepo {
+    pub fn init(path: &Path, cwd: &Path) -> CargoResult<FossilRepo> {
+        // fossil doesn't create the directory so we'll do that first
+        create_dir(path)?;
+
+        // set up the paths we'll use
+        let db_fname = ".fossil";
+        let mut db_path = path.to_owned();
+        db_path.push(db_fname);
+
+        // then create the fossil DB in that location
+        process("fossil").cwd(cwd).arg("init").arg(&db_path).exec()?;
+
+        // open it in that new directory
+        process("fossil").cwd(&path).arg("open").arg(db_fname).exec()?;
+
+        // set `target` as ignoreable and cleanable
+        process("fossil").cwd(cwd).arg("settings")
+            .arg("ignore-glob")
+            .arg("target");
+        process("fossil").cwd(cwd).arg("settings")
+            .arg("clean-glob")
+            .arg("target");
+        Ok(FossilRepo)
+    }
+}